package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.entity.SetmealDish;
import com.itheima.reggie.mapper.SetmealDishMapper;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.service.SetmealDishService;
import com.itheima.reggie.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Xiao
 * @date 2021/9/27
 */
@Service
@Slf4j
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {
    /**
     * 添加套餐菜品数据
     * @param setmealDish
     * @return
     */
    @Override
    public boolean addSetmealDish(SetmealDish setmealDish) {
        return this.save(setmealDish);
    }

    /**
     * 根据套餐id查找菜品数据
     * @param setmealId
     * @return
     */
    @Override
    public List<SetmealDish> querySetmealDishsBySetmealId(Long setmealId) {
        LambdaQueryWrapper<SetmealDish> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SetmealDish::getSetmealId, setmealId);
        return this.list(wrapper);
    }

    /**
     * 根据套餐id删除关联的菜品数据
     * @param setmealId
     * @return
     */
    @Override
    public boolean removeBySetmealId(Long setmealId) {
        LambdaQueryWrapper<SetmealDish> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SetmealDish::getSetmealId, setmealId);
        return this.remove(wrapper);
    }

    /**
     * 批量添加套餐菜品数据
     * @param setmealDishes
     * @return
     */
    @Override
    public boolean addSetmealDishs(List<SetmealDish> setmealDishes) {
        return this.saveBatch(setmealDishes);
    }

    /**
     * 根据套餐ids批量删除关联的菜品数据
     * @param setmealids
     * @return
     */
    @Override
    public void removeBySetmealIds(List<Long> setmealids) {
        LambdaQueryWrapper<SetmealDish> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(SetmealDish::getSetmealId, setmealids);
        this.remove(wrapper);
    }
}
